package com.tuling.designpattern.memento;

/**
 * @author it-小林
 * @desc  棋子类 原发器角色
 * @date 2021年09月18日 15:10
 */
public class Chessman {

    private String label;

    private Integer x;

    private Integer y;

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    public Chessman(String label, Integer x, Integer y) {
        this.label = label;
        this.x = x;
        this.y = y;
    }

    /**
     * 保存状态
     * @return
     */
    public ChessmanMemento save(){
        return new ChessmanMemento(this.label, this.x, this.y);
    }

    /**
     * 恢复
     * @param chessmanMemento
     */
    public void restore(ChessmanMemento chessmanMemento){
        this.label = chessmanMemento.getLabel();
        this.x = chessmanMemento.getX();
        this.y = chessmanMemento.getY();
    }

    /**
     * 输出
     */
    public void show(){
        System.out.println(String.format("棋子<%s>:当前位置为：<%d, %d>", this.getLabel(), this.getX(), this.getY()));
    }
}
